// Win32SmartDeviceProject1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <gtest/gtest.h>
#include <windows.h>
#include <commctrl.h>
#include <iostream>
#include <comdef.h>
#include <stdio.h>
#include <afx.h>

using namespace std;


int times=5;


class Audio
{
public:
	int playMusic(DWORD dword);
	int printAudioProp();
};

int Audio::playMusic(DWORD dword)
{
	try
	{
		cout<<"--------------------------------------------------------"<<endl;
		cout<<"ready to play sound"<<endl;
		if(waveOutSetVolume(0,dword))
		{
			return 0;
		}

		for(int i=0;i<times;++i)
		{
			PlaySound(TEXT("SystemStart"), NULL, SND_ALIAS);
		}
		cout<<"stop to play sound"<<endl;
		return 1;
	}
	catch (CException* e)
	{
		return 0;
	}
}

int Audio::printAudioProp()
{
	int waveDevice;
	waveDevice = (int)waveOutGetNumDevs();

	cout<<"waveDevice:"<<waveDevice<<endl;

	WAVEOUTCAPS waveCap[10];

	if(waveDevice == 0)
	{
		cout<<"there's no wave device"<<endl;
		return 0;
	}
	else
	{
		try
		{
			cout<<"--------------------------------------------------------"<<endl;
			for(int i = 0;i<waveDevice;++i)
			{
				cout<<endl;
				cout<<"Device:"<<i<<endl;
				cout<<"waveOutGetDevCaps:"<<endl;
				waveOutGetDevCaps(i,&waveCap[i],sizeof(WAVEOUTCAPS));
				cout<<"format support:"<<waveCap[i].dwFormats<<endl;
				cout<<"product name:"<<waveCap[i].szPname<<endl;
				cout<<"version of the driver:"<<waveCap[i].vDriverVersion<<endl;
				cout<<"manufacturer ID:"<<waveCap[i].wMid<<endl;
				cout<<"product ID:"<<waveCap[i].wPid<<endl;

				cout<<endl<<"waveOutGetProperty:"<<endl;
				const GUID* pPropSetId;
				ULONG       ulPropId;
				LPVOID      pvPropParams;
				ULONG       cbPropParams;
				LPVOID      pvPropData;
				ULONG       cbPropData;
				PULONG      pcbReturn;
				waveOutGetProperty(i,pPropSetId,ulPropId,pvPropParams,cbPropParams,pvPropData,cbPropData,pcbReturn);
				cout<<"Globally Unique Identifier"<<pPropSetId<<endl;

				//DWORD volume=0;
				//waveOutGetVolume(0,&volume);
			}
			return 1;
		}
		catch (CException* e)
		{
			return 0;
		}

	}
}

int _tmain(int argc, _TCHAR* argv[])
{
	cout<<"beginning"<<endl;
	for(int i =0;i<argc;++i)
	{
		wcout<<argv[i]<<endl;
	};
	cout<<endl<<endl<<endl;
	
	times = _ttoi(argv[argc-1]);
	cout<<times<<endl;

	testing::InitGoogleTest(&argc, argv);
	return RUN_ALL_TESTS();
}

class AudioTest : public testing::Test
{
protected:
	static void SetUpTestCase()
	{
		audio = new Audio();
		cout<<"start"<<endl;
	}
	static void TearDownTestCase()
	{
		delete audio;
	}
	static Audio* audio;
};
Audio* AudioTest::audio = NULL;

TEST_F(AudioTest,PlayMusic)
{
	EXPECT_EQ(1,audio->playMusic(0xFFFFFFFF));
	Sleep(3000);
}

TEST_F(AudioTest,getAudioProp)
{
	EXPECT_EQ(1,audio->printAudioProp());
	Sleep(3000);
}

TEST_F(AudioTest,decrease)
{
	EXPECT_EQ(1,audio->playMusic(0x99999999));
	Sleep(3000);
}


TEST_F(AudioTest,Increase)
{
	EXPECT_EQ(1,audio->playMusic(0xFFFFFFFF));
	Sleep(3000);
}
